package com.gec.hawaste.controller;


import com.gec.hawaste.entity.Statute;
import com.gec.hawaste.service.IStatuteService;
import com.gec.hawaste.utils.PageInfo;
import com.gec.hawaste.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lisongsong
 * @since 2022-04-21
 */
@RestController
@RequestMapping("manager/statute")
public class StatuteController {
    @Autowired
    private IStatuteService iStatuteService;
    // 根据type 去查询 法律法规列表 和分页
    @RequestMapping("select/{current}/{size}")
    public ResultBean<PageInfo> select(@PathVariable("current") Integer current,
                                       @PathVariable("size") Integer size,
                                       @RequestParam(name = "type",required = false) Integer type)
    {
        // 设置分页
        PageInfo<Statute> pageInfo = new PageInfo<Statute>(current,size);

        //     public IPage<Statute> selectByCondition(IPage<Statute> page,Integer type);
        pageInfo = (PageInfo<Statute>) this.iStatuteService.selectByCondition(pageInfo,type);

        // 设置分页导航条
        pageInfo.setNavigatePage();

        return ResultBean.ok(pageInfo);
    }
    // 根据id 去查询出当前一个 法律法规
    // /manager/statute/selectOne'
    @RequestMapping("selectOne")
    public ResultBean<Statute> selectOne(Long id)
    {
        Statute statute = this.iStatuteService.getById(id);
        return ResultBean.ok(statute);
    }

    // 保存和更新
    //  /manager/statute/saveOrUpdate
    @RequestMapping("saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody Statute statute)
    {
        this.iStatuteService.saveOrUpdate(statute);
        return ResultBean.ok();
    }
    //删除
    @RequestMapping("deleteOne")
    public ResultBean delete(long id){
        this.iStatuteService.removeById(id);
        return ResultBean.ok();
    }


}
